<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>登 录</title>
    <!-- 样 式 文 件 -->
    <link rel="stylesheet" href="/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="/admin/css/other/login.css"/>
    <!-- 这里设定了项目根路径,后面使用到路径的地方正常填写即可 -->
    <!--    <base th:href="${#request.getContextPath()}+'/'">-->
    <link rel="icon" href="/img/12441676731246_.pic_thumb.jpg">
    <style>
        input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill {
            -webkit-box-shadow: 0 0 0 1000px white inset;
        }
    </style>
</head>
<!-- 代 码 结 构 -->
<body style="background-size: cover;background-image:url('/admin/images/background.svg')">
<form class="layui-form" action="javascript:void(0);">
    <div class="layui-form-item">
        <img class="logo" src="/admin/images/文件柜.png"/>
        <div class="title">文 件 柜 系 统</div>
    </div>
    <div class="layui-form-item">
        <input id="username" name="username" autocomplete="off" placeholder="用 户 名 : " type="text" hover
               class="layui-input" required
               lay-verify="username"/>
    </div>
    <div class="layui-form-item">
        <input id="password" name="password" autocomplete="off" placeholder="密 码 : " type="password" hover
               class="layui-input" required
               lay-verify="password"/>
    </div>
    <!--			<div class="layui-form-item">-->
    <!--				<input placeholder="验证码 : " name="captcha" id="captcha" hover class="code layui-input layui-input-inline"  required lay-verify="captcha" />-->
    <!--				<img src="captcha" class="captchaImage" id="captchaImage" onclick="this.src=this.src+'?'+Math.random()" title="点击刷新"/>-->
    <!--				<img src="/erp/captcha" class="captchaImage" id="captchaImage" onclick="this.src=this.src+'?'+Math.random()" title="点击刷新"/>-->
    <!--			</div>-->
<!--    <div class="layui-form-item">-->
<!--        <input type="checkbox" id="rememberme" name="rememberme" title="记住密码" lay-skin="primary" checked>-->
<!--    </div>-->
    <div class="layui-form-item">
        <button class="pear-btn pear-btn-success login" lay-submit lay-filter="formLogin">
            登 入
        </button>
    </div>
</form>
<!-- 资 源 引 入 -->
<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
    layui.use(['form', 'button', 'popup'], function () {
        var form = layui.form;
        var button = layui.button;
        var popup = layui.popup;
        var $ = layui.jquery;

        // Session过期，如何跳出iframe框架页的问题
        if(window !=top){
            top.location.href=location.href;
        }
        // 本地开发使用
        // $.ajax({
        //     url: 'login',
        //     type: 'post',
        //     dataType: 'text',
        //     data: {
        //         username: "admin",
        //         password: "123456",
        //         captcha: $('#captcha').val(),
        //         rememberme: $('#rememberme').val()
        //     },
        //     success: function (result) {
        //         location.href = "index";
        //     }
        // })

        form.verify({
            username: function (value) {
                if (value.length <= 0) {
                    return '用户名不能为空';
                }
            },
            password: function (value) {
                if (value.length <= 0) {
                    return '密码不能为空';
                }
            },
            captcha: function (value) {
                if (value.length <= 0) {
                    return '验证码不能为空';
                }
                if (value.length !== 4) {
                    return '请输入正确格式的验证码';
                }
            }
        })

        form.on('submit(formLogin)', function () {
            $.ajax({
                url: 'login',
                type: 'post',
                dataType: 'text',
                data: {
                    username: $('#username').val(),
                    password: $('#password').val(),
                    captcha: $('#captcha').val(),
                    rememberme: $('#rememberme').val()
                },
                success: function (result) {
                    var resultJson = JSON.parse(result)
                    if (resultJson.code === 200) {
                        // layui.data("token", {
                        // 	key: "Authorization",
                        // 	value: "Bearer "+ restjson.jwt
                        // });
                        location.href = "index";
                    } else {
                        layer.msg(resultJson.message, {icon: 2, time: 1000}, function () {
                            $("#captchaImage").attr("src", "captcha" + "?" + Math.random());
                        });
                        return false;
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>
